<div class="btn-group">
    @if($delivery->status == 1)
        @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os.labels'))
            <button style="margin-left: 5px;" class="btn btn-sm btn-info upload-modal" data-id="{{ $id }}" data-action="uploadLabels"><i class="fa fa-upload"></i>&nbsp;上传标签</button>
            <button style="margin-left: 5px;" class="btn btn-sm btn-warning form-action" data-id="{{ $id }}" data-action="uploadedLabels"><i class="fa fa-briefcase"></i>&nbsp;标签上传完成</button>
        @endif
        @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os.delete'))
            <button style="margin-left: 5px;" class="btn btn-sm btn-danger os-del" data-id="{{ $id }}"><i class="fa fa-remove"></i>&nbsp;删除</button>
        @endif
    @endif
    @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os.ship'))
        @if($delivery->status == 2)
            <button class="btn btn-sm btn-info common-modal" data-id="{{ $id }}" data-action="startPreparing"><i class="fa fa-briefcase"></i>&nbsp;开始备货</button>
        @elseif($delivery->status == 3)
            <button class="btn btn-sm btn-info common-modal" data-id="{{ $id }}" data-action="preparing"><i class="fa fa-briefcase"></i>&nbsp;备货</button>
            <button style="margin-left: 5px;" class="btn btn-sm btn-warning form-action" data-id="{{ $id }}" data-action="prepared"><i class="fa fa-briefcase"></i>&nbsp;备货完成</button>
        @endif
    @endif
    @if($delivery->status == 4 && \Encore\Admin\Facades\Admin::user()->can('os-in.os.box'))
         <a href="/xqc/overseas-in/os-dropshipping/{{ $id }}/box" class="btn btn-sm btn-info"><i class="fa fa-upload"></i>&nbsp;录入装箱信息</a>
    @endif
    @if($delivery->status == 5 && \Encore\Admin\Facades\Admin::user()->can('os-in.os.ship'))
        <button class="btn btn-sm btn-info form-action" data-id="{{ $id }}" data-action="ship"><i class="fa fa-upload"></i>&nbsp;发货</button>
    @endif
    @if(in_array($delivery->status,[2,3,4,5]) && \Encore\Admin\Facades\Admin::user()->can('os-in.os.back-labels'))
        <button style="margin-left: 5px;" class="btn btn-sm btn-default os-back" data-id="{{ $id }}">返回标签上传</button>
    @endif
    @if($delivery->status >= 6 && \Encore\Admin\Facades\Admin::user()->can('os-in.os.logistics'))
        <button style="margin-left: 5px;" class="btn btn-sm btn-info wuliu-modal" data-id="{{ $id }}" data-action="logistics"><i class="fa fa-edit"></i>&nbsp;更新物流</button>
    @endif
    @if($delivery->status > 4)
        <a href="/xqc/overseas-in/os-dropshipping-box/{{ $id }}/download" target="_blank" style="margin-left: 5px;" class="btn btn-sm btn-default"><i class="fa fa-download"></i>&nbsp;导出装箱信息</a>
    @endif
    @if(\Encore\Admin\Facades\Admin::user()->can('os.download'))
        <a href="/xqc/overseas-in/os-dropshipping/{{ $id }}/download" target="_blank" class="btn btn-sm btn-default">下载</a>
    @endif
</div>
@include('overseas-in.os-dropshipping-edit.modal-temp-upload')
@include('overseas-in.os-dropshipping-edit.modal-temp-common')
@include('overseas-in.os-dropshipping-edit.modal-temp-wuliu')
<script language="JavaScript" type="text/javascript">
    $(function () {
        var _ajax = function (action,param) {
            $.ajax({
                method: 'post',
                url: '/xqc/overseas-in/os-dropshipping-ajax',
                data: {
                    _token: "{{ csrf_token() }}",
                    action:action,
                    param:param
                },
                success: function (data) {
                    if (typeof data === 'object') {
                        if (data.status) {
                            toastr.success('提交成功 !');
                            $.pjax.reload('#os-delivery-form');
                        } else {
                            swal(data.message, '', 'error');
                        }
                    }
                }
            });
        };
        var _ajaxConfirm = function(action,param,resolve){
            $.ajax({
                method: 'post',
                url: '/xqc/overseas-in/os-dropshipping-ajax',
                data: {
                    _token: "{{ csrf_token() }}",
                    action: action,
                    param: param
                },
                success: function (data) {
                    resolve(data);
                }
            });
        };
        $('.os-del').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            swal({
                title: "确定删除？",
                text : "确定要删除此单吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        _ajaxConfirm('osDel',id,resolve)
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        toastr.success('删除成功 !');
                        location.href = '/xqc/overseas-in/os-dropshipping';
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });
        //返回标签上传
        $('.os-back').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            swal({
                title: "确定返回？",
                text : "确定要返回上传标签吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        _ajaxConfirm('backUploadLabels',id,resolve)
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        toastr.success('提交成功 !');
                        $.pjax.reload('#os-delivery-form');
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });

        //发货，备货完成，标签上传完成
        $('.form-action').unbind('click').click(function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            var action = $(this).data('action');
            _ajax(action,id);
        });

        $('.upload-modal').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            var action = $(this).data('action');
            $("#uploadModal").modal({
                remote : '/xqc/overseas-in/os-dropshipping-modal?param=' + id + '&action=' + action
            });
        });

        $("#uploadModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });

        $('.common-modal').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            var action = $(this).data('action');
            $("#commonModal").modal({
                remote : '/xqc/overseas-in/os-dropshipping-modal?param=' + id + '&action=' + action,
            });
        });
        $("#commonModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });

        $('.wuliu-modal').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            var action = $(this).data('action');
            $("#wuliuModal").modal({
                remote : '/xqc/overseas-in/os-dropshipping-modal?param=' + id + '&action=' + action,
            });
        });
        $("#wuliuModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });
    });
</script>
